/* eslint-disable react-hooks/exhaustive-deps */
import React, { useState, useEffect } from 'react';
import { Table, Space } from 'antd';
import { Link, useHistory } from 'react-router-dom';
import Cookies from 'js-cookie';
import qs from 'qs';
import { If } from 'babel-plugin-jsx-control-statements';
import RequestApi from '@/utils/request';
import css from './index.scss';

/**
 * 资料初审待处理
 * -
 */
export default (props) => {
	const { index } = props;
	const distinctId = Cookies.get('distinctId');
	const [data, setData] = useState();
	const history = useHistory();
	const search = qs.parse(history.location.search, { ignoreQueryPrefix: true });
	const { stage, name } = search;
	useEffect(() => {
		RequestApi.connection(
			'get',
			`/parkLotRecordTask/getManageAuditList/${stage}/${index}/${distinctId}/${1}/${20}`
		).then((response) => {
			setData(response.data);
		});
	}, []);
	const columns = [
		{
			title: '功能列',
			dataIndex: 'id',
			render: (text, record) => {
				return (
					<Space>
						<Link
							to={{
								pathname: `/audit`,
								search: qs.stringify({ name, id: record.id, value: 1, type: record.type, stage: record.stage }),
							}}
						>
							审核
						</Link>
						<Link
							to={{
								pathname: `/parking-record/check`,
								search: qs.stringify({ id: record.id, value: 1, type: record.type, stage: record.stage }),
							}}
						>
							详情
						</Link>
						<Link
							to={{
								pathname: `/parking-record/check`,
								search: qs.stringify({ id: record.id, value: 2, type: record.type, stage: record.stage }),
							}}
						>
							流程履历
						</Link>
					</Space>
				);
			},
		},
		{
			title: '停车场名',
			dataIndex: 'name',
		},
		{
			title: '办结剩余时限',
			dataIndex: 'nodeDays',
		},
		{
			title: '备案项目',
			dataIndex: 'auditStatus',
			render: (text) => {
				return (
					<span>
						{text === 0
							? '暂存'
							: text === 1
							? '待初审'
							: text === 2
							? '初审不通过'
							: text === 3
							? '待现场勘察'
							: text === 4
							? '现场勘察不通过'
							: text === 5
							? '待复审'
							: text === 6
							? '复审不通过'
							: text === 7
							? '待编号制证(备案成功)'
							: text === 8
							? '待证件打印(制证成功)'
							: text === 9
							? '证件打印成功'
							: null}
					</span>
				);
			},
		},
		{
			title: '所在环节',
			dataIndex: 'stage',
			render: (text) => {
				return (
					<span>
						{text === 0
							? '在线提交备案信息'
							: text === 1
							? '区停车办资料初核'
							: text === 2
							? '区停车办现场勘察'
							: text === 3
							? '区市镇级备案审核'
							: null}
					</span>
				);
			},
		},
		{
			title: '状态',
			dataIndex: 'status',
			render: (text) => {
				return (
					<span>
						{text === 0
							? '暂存'
							: text === 1
							? '审核中'
							: text === 2
							? '已退回'
							: text === 3
							? '已废弃'
							: text === 4
							? '已完成(审核流程完成)'
							: null}
					</span>
				);
			},
		},
		{
			title: '流水号',
			dataIndex: 'sno',
		},
		{
			title: '所在区域',
			dataIndex: 'districtName',
		},
		{
			title: '申请时间',
			dataIndex: 'submitTime',
		},
		{
			title: '完成时间',
			dataIndex: 'finishedTime',
		},
	];
	return (
		<If condition={data !== undefined}>
			<div className={css.app}>
				<h1>
					待处理
					{index}
				</h1>
				<Table columns={columns} dataSource={data} />
			</div>
		</If>
	);
};
